﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <input type="text" id="txtOne" />
    <input type="button" id="btnOne" value="发送内容" />
    <p id="result"></p>
    <!--依赖文件-->
    <script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/signalr.js/2.2.2/jquery.signalR.min.js"></script>
    <!--加载hub客户端js代理 -->
    <script src="/signalr/hubs"></script>  
    <script>
        //创建 MsgHub js实例  
        $.connection.hub.url = "/signalr";
        // Set the name
        $.connection.hub.qs = "name=WebClient";

        var msgHub = $.connection.msgHub;
        //启用客户端日志  
        $.connection.hub.logging = true;

        //注册客户端接收事件处理  
        msgHub.client.receive = function (content) {
            console.info(content);
            $('#result').append('服务器推送内容：' + content).append('<br />');
        }

        //启动监听  
        $.connection.hub.start().done(function () {
            //调用服务端发送消息  
            $('#btnOne').click(function () {
                var text = $('#txtOne').val();
                msgHub.server.send(text);
                //msgHub.server.sendPrivateMessage("ConsoleClient", text);
            });
        });
    </script>
</body>
</html>
